<?php
/**
 * Main module file
 *
 * Main module
 *
 * @author Serge Rodovnichenko <sergerod@gmail.com>
 * @version 0.1
 * @license MIT
 */

if (!defined('_PS_VERSION_'))
    exit;

 class Regional_Carrier extends CarrierModule {

     /**
      * Constructor
      */
     public function __construct()
     {
         $this->name='regional_carrier';
         $this->tab='shipping_logistics';
         $this->version='1.0.0';
         $this->author='Serge Rodovnichenko';

         parent::__construct();

         $this->displayName='Regional Carriers';
         $this->description=$this->l('Offer your customers different carriers depending on their countriy or region');

     }

     /**
      * Install method
      */
     public function install()
     {

         if (!parent::install() || !$this->registerHook('updateCarrier'))
             return false;

        return true;
     }

     /**
      * Uninstall method
      */
    public function uninstall()
    {
        if(!parent::uninstall() || !$this->unregisterHook('updateCarrier'))
            return false;
        
        return true;
    }

    /**
     *
     */
    public function getContent()
    {
        $output = "<h2>{$this->displayName}</h2>";
        return $output . $this->displayForm();
    }

    /**
     *
     */
    private function _displayForm()
    {
        return "<form></form>";
    }

    /**
     * 
     * @param array $params
     * @param float $shipping_cost
     */
    public function getOrderShippingCost($params, $shippingCost)
    {
        return false;
    }

    /**
     *
     * @param array $params
     */
    public function getOrderShippingCostExternal($params)
    {
        return false;
    }

    /**
     *
     * @param array $params array('id_carrier' (старый номер), $carrier (объект с id новым), 'cookie' (объект класса Cookie), 'cart', 'altern' (int))
     */
    public function hookupdateCarrier($params)
    {
        Db::getInstance()->autoExecute("{_DB_PREFIX_}regional_carrier_services", array('id_carrier'=>$params['carrier']->id),'UPDATE', "`id_carrier`=".(int)$params['id_carrier']);
    }

 }
